﻿
Partial Class WebForm_AddControl_SearchUOrganizationControlV2
    Inherits System.Web.UI.UserControl

    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.BindGV(Me.ddlOrganization.SelectedValue)
    End Sub
    Protected Sub chkorg_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim RowIndex As Integer = DirectCast(DirectCast(sender, CheckBox).NamingContainer, GridViewRow).RowIndex
        Me.UOrganizationID = TryCast(Me.gv.Rows(RowIndex).FindControl("lblUOrganizationID"), Label).Text
        Me.OrganizationName = TryCast(Me.gv.Rows(RowIndex).FindControl("chkorg"), CheckBox).Text
        Me.VOrganizationID = TryCast(Me.gv.Rows(RowIndex).FindControl("lblVOrganizationID"), Label).Text
        Me.VOrganizationName = TryCast(Me.gv.Rows(RowIndex).FindControl("lblVOrganizationName"), Label).Text
        Me.VolunteerID = TryCast(Me.gv.Rows(RowIndex).FindControl("lblVolunteerID"), Label).Text
        Me.VolunteerName = TryCast(Me.gv.Rows(RowIndex).FindControl("lblVolunteerName"), Label).Text
        Me.OfficePhone = TryCast(Me.gv.Rows(RowIndex).FindControl("lblOfficePhone"), Label).Text
        RaiseEvent SelectedIndexChanged(Me, New EventArgs)
    End Sub
    Protected Sub gv_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gv.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then

        End If
    End Sub

    'Protected Sub gv_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gv.RowCommand
    '    If e.CommandName = "Select" Then
    '        Dim rowIndex As Integer = e.CommandArgument
    '        'Me.SelectedEmployeeID = Me.gv.DataKeys(rowIndex)("EmployeeID")
    '        Me.UOrganizationID = TryCast(Me.gv.Rows(rowIndex).FindControl("lblUOrganizationID"), Label).Text
    '        Me.OrganizationName = TryCast(Me.gv.Rows(rowIndex).FindControl("lblOrganizationName"), Label).Text
    '        Me.VOrganizationID = TryCast(Me.gv.Rows(rowIndex).FindControl("lblVOrganizationID"), Label).Text
    '        Me.VOrganizationName = TryCast(Me.gv.Rows(rowIndex).FindControl("lblVOrganizationName"), Label).Text
    '        Me.VolunteerID = TryCast(Me.gv.Rows(rowIndex).FindControl("lblVolunteerID"), Label).Text
    '        Me.VolunteerName = TryCast(Me.gv.Rows(rowIndex).FindControl("lblVolunteerName"), Label).Text
    '        Me.OfficePhone = TryCast(Me.gv.Rows(rowIndex).FindControl("lblOfficePhone"), Label).Text
    '        RaiseEvent SelectedIndexChanged(Me, New EventArgs)
    '    End If
    'End Sub

    Protected Sub ddlOrganization_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlOrganization.SelectedIndexChanged
        Me.BindGV(Me.ddlOrganization.SelectedValue)
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            '  Me.BindDDLOrganizationID()
        End If
    End Sub

    Protected Sub ddlOrganization_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlOrganization.Init
        Me.BindDDLOrganizationID()
    End Sub
End Class

Partial Class WebForm_AddControl_SearchUOrganizationControlV2
    Public Sub Show(ByVal DirectUOrganizationID As String)
        Me.DirectUOrganizationID = DirectUOrganizationID
        Me.BindGV(Me.ddlOrganization.SelectedValue)
    End Sub
    Private Sub BindDDLOrganizationID()
        'Dim dat As New clsData
        'Dim sql As New MyOrganizationDataFilter
        'sql.AppendFormat("select o.OrganizationName,o.UOrganizationID from OrganizationView o ")
        'sql.AppendFormat("where OrganizationType <> 'V' and Active='Y' ")
        'sql.AppendFormat("order by OrganizationName ")
        Me.ddlOrganization.DataTextField = "OrganizationName"
        Me.ddlOrganization.DataValueField = "UOrganizationID"
        Me.ddlOrganization.DataSource = MyObj.GetOrganizationData(False)
        Me.ddlOrganization.DataBind()
        Me.ddlOrganization.Items.Insert(0, MyObj.GetDDLPleaseChooseItem())

        Me.ddlOrganization.SelectedValue = clsAuth.GetUser().UOrganizationID
    End Sub
    Private Sub BindGV(ByVal DirectUOrganizationID As String)
        Dim dat As New clsData
        Dim sql As New MyOrganizationDataFilter

        sql.Length = 0
        sql.AppendFormat(" select vo.DirectUOrganizationID,ov.OrganizationName,vo.VOrganizationID,vo.VOrganizationName,'-1,'+cast(vo.VOrganizationID as nvarchar(50) ) as UOrganizationID  ")
        sql.AppendFormat(" ,v.VolunteerID,v.VolunteerName,v.OfficePhone ")
        sql.AppendFormat(" from OtherOrganizationMapping oom ")
        sql.AppendFormat(" inner join VOrganizationViewV2 vo ")
        sql.AppendFormat(" on oom.UOrganizationID = '-1,'+cast(vo.VOrganizationID as nvarchar(50) ) ")
        sql.AppendFormat(" inner join Volunteer v ")
        sql.AppendFormat(" on oom.UserID=v.VolunteerID ")
        sql.AppendFormat(" inner join OrganizationView ov on vo.DirectUOrganizationID=ov.UOrganizationID ")
        sql.AppendFormat(" where oom.Source = 'VolunteerLeader' ")
        If Not DirectUOrganizationID = "" AndAlso Not DirectUOrganizationID = "0" Then
            sql.AppendFormat(" and vo.DirectUOrganizationID = '{0}' ", DirectUOrganizationID)
        End If

        Me.gv.DataSource = dat.GetData(sql)
        Me.gv.DataBind()

        Me.Visible = True
        Me.mpSearch.Show()
    End Sub

    Public Property DirectUOrganizationID() As String
        Get
            Return ViewState("DirectUOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("DirectUOrganizationID") = value
        End Set
    End Property

    Public Property UOrganizationID() As String
        Get
            Return ViewState("UOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("UOrganizationID") = value
        End Set
    End Property

    Public Property OrganizationName() As String
        Get
            Return ViewState("OrganizationName")
        End Get
        Set(ByVal value As String)
            ViewState("OrganizationName") = value
        End Set
    End Property

    Public Property VOrganizationID() As String
        Get
            Return ViewState("VOrganizationID")
        End Get
        Set(ByVal value As String)
            ViewState("VOrganizationID") = value
        End Set
    End Property

    Public Property VOrganizationName() As String
        Get
            Return ViewState("VOrganizationName")
        End Get
        Set(ByVal value As String)
            ViewState("VOrganizationName") = value
        End Set
    End Property

    Public Property VolunteerID() As String
        Get
            Return ViewState("VolunteerID")
        End Get
        Set(ByVal value As String)
            ViewState("VolunteerID") = value
        End Set
    End Property

    Public Property VolunteerName() As String
        Get
            Return ViewState("VolunteerName")
        End Get
        Set(ByVal value As String)
            ViewState("VolunteerName") = value
        End Set
    End Property

    Public Property OfficePhone() As String
        Get
            Return ViewState("OfficePhone")
        End Get
        Set(ByVal value As String)
            ViewState("OfficePhone") = value
        End Set
    End Property

    Public Event SelectedIndexChanged(ByVal source As Object, ByVal e As EventArgs)
End Class
